﻿using CommandProcessor.Command;
using Data.Infrastructure;
using Data.Repositories;
using Domain.Commands;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Domain.Handlers
{
    public class DeletePurchaseHandler : ICommandHandler<DeletePurchaseCommand>
    {
        private readonly IPurchaseRepository purchaseRepository;
        private readonly IUnitOfWork unitOfWork;
        public DeletePurchaseHandler(IPurchaseRepository purchaseRepository, IUnitOfWork unitOfWork)
        {
            this.purchaseRepository = purchaseRepository;
            this.unitOfWork = unitOfWork;
        }
        public ICommandResult Execute(DeletePurchaseCommand command)
        {
            var purchase = purchaseRepository.GetById(command.ID);
            purchaseRepository.Delete(purchase);
            unitOfWork.Commit();
            return new CommandResult(true);
        }


        public ICommandResult ExecuteRange(IEnumerable<DeletePurchaseCommand> commands)
        {
            var ids = commands.Select(y => y.ID);
            purchaseRepository.Delete(x => ids.Contains(x.ID));
            unitOfWork.Commit();
            return new CommandResult(true);
        }
        public ICommandResult DeleteRange(IEnumerable<DeletePurchaseCommand> commands)
        {
            throw new NotImplementedException();
        }
    }
}
